﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace SASS.Sociales.DAL
{
       public abstract class SIASSClaseBase
    {

        #region Funciones

        protected System.Object checkNull(string asValue)
        {

            if (asValue == "")
            {
                return "null";
            }
            else
            {
                return "'" + asValue + "'";
            }
        }

        protected System.Object checkNull(DateTime adtValue)
        {
            if (adtValue == DateTime.MinValue)
            {
                return null;
            }
            else
            {
                return adtValue;
            }
        }

        protected System.Object checkNull(System.Object aoValue)
        {

            if (aoValue == DBNull.Value)
            {
                return null;
            }
            else
            {
                if (aoValue.GetType() == typeof(DateTime))
                {
                    DateTime aoDate = Convert.ToDateTime(aoValue);
                    if (aoDate == DateTime.MinValue)
                    {
                        return DBNull.Value;
                    }
                    else
                    {
                        return aoDate;
                    }
                }
                else if (aoValue.GetType() == typeof(string))
                {
                    string asValue = Convert.ToString(aoValue);
                    if (asValue == "")
                    {
                        return DBNull.Value;
                    }
                    else
                    {
                        return asValue;
                    }
                }
                else
                {
                    return aoValue;
                }
            }

        }

        protected string checkNullInt(System.Object intValue)
        {
            if (intValue == null)
            {
                return "null";
            }
            else
            {
                return intValue.ToString();
            }
        }

        protected string checkNullDecimal(System.Object decValue)
        {
            if (decValue == null)
            {
                return "null";
            }
            else
            {
                return decValue.ToString();
            }
        }


        protected string getStringValue(IDataReader dr, int intCampo)
        {
            if (dr.IsDBNull(intCampo))
            {
                return "";
            }
            else
            {
                return dr.GetString(intCampo);
            }
        }

        protected DateTime getDateValue(IDataReader dr, int intCampo)
        {
            if (dr.IsDBNull(intCampo))
            {
                return DateTime.MinValue;
            }
            else
            {
                return dr.GetDateTime(intCampo);
            }
        }

        protected System.Object getNumericValue(IDataReader dr, int intCampo)
        {
            if (dr.IsDBNull(intCampo))
            {
                return 0;
            }
            else
            {
                return dr.GetValue(intCampo);
            }
        }

        protected System.Object getDecimalValue(IDataReader dr, int intCampo)
        {
            if (dr.IsDBNull(intCampo))
            {
                return 0;
            }
            else
            {
                return dr.GetDecimal(intCampo);
            }
        }

        protected string setDateValue(DateTime adtValue)
        {
            StringBuilder sb = new StringBuilder();
            //sb.Append(((DateTime)adtValue).ToString("dd/MM/yyyy HH:mm:ss"));
            //sb.Append(((DateTime)adtValue).ToString("yyyy-MM-dd HH:mm:ss"));
            sb.Append(((DateTime)adtValue).ToString("yyyyMMdd HH:mm:ss"));
            return Convert.ToString(sb);
        }
        #endregion

    }
}
